package com.lantosec.hmrp.modules.archives.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.archives.entity.UserHouse;
import com.lantosec.hmrp.modules.archives.service.IUserHouseService;
import com.lantosec.hmrp.modules.archives.vo.UserHouseVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 领导干部本人、配偶及共同生活的子女住房情况表 控制器
 *
 * @author AutoCode
 * @since 2020-06-12
 */
@Api(value = "领导干部本人、配偶及共同生活的子女住房情况表控制器", tags = "领导干部本人、配偶及共同生活的子女住房情况表控制器")
@RestController
@RequestMapping("/archives/user/house")
@Log4j2
public class UserHouseController extends BaseController {
    @Autowired
    private IUserHouseService service;

    @GetMapping("getUserHouse/{userId}")
    @ApiOperation(value = "查询领导干部住房情况信息")
    public Result<List<UserHouseVO>> getUserHouse(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserHouseVO> userHouseVOList = service.getUserHouse(userId);
        return Result.ok(userHouseVOList);
    }

    @GetMapping("getUserHouseVerify/{userId}")
    @ApiOperation(value = "查询领导干部住房情况信息审核列表")
    public Result<List<UserHouseVO>> getUserHouseVerify(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserHouseVO> userHouseVOList = service.getUserHouseVerify(userId);
        return Result.ok(userHouseVOList);
    }

    @PutMapping("verifyUserHouse")
    @ApiOperation(value = "审核")
    public Result<Void> verifyUserHouse(@ApiParam(value = "用户任职信息表VO对象", required = true) @RequestBody UserHouseVO vo) {
        service.verifyUserHouse(vo);
        return Result.ok();
    }

    @GetMapping("getUserHouseHistory/{userId}")
    @ApiOperation(value = "查询领导干部住房情况信息历史列表")
    public Result<List<UserHouseVO>> getUserHouseHistory(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserHouseVO> userHouseVOList = service.getUserHouseHistory(userId);
        return Result.ok(userHouseVOList);
    }

    @PostMapping("create")
    @ControllerLog(name = "新增领导干部本人、配偶及共同生活的子女住房情况", type = LogType.add)
    @ApiOperation(value = "新增数据")
    public Result<String> create(@ApiParam(value = "领导干部本人、配偶及共同生活的子女住房情况表VO对象", required = true) @RequestBody @Validated UserHouseVO vo){
        service.saveUserHouse(vo);
        return Result.ok();
    }

    @PutMapping("update")
    @ControllerLog(name = "修改领导干部本人、配偶及共同生活的子女住房情况", type = LogType.update)
    @ApiOperation(value = "修改数据")
    public Result<Void> update(@ApiParam(value = "领导干部本人、配偶及共同生活的子女住房情况表VO对象", required = true) @RequestBody UserHouseVO vo){
        service.updateUserHouse(vo);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除领导干部本人、配偶及共同生活的子女住房情况", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
